package com.cat.binaryTree;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/merge-nodes-in-between-zeros/
 * @create 2025/9/9 18:04
 * @since JDK17
 */

public class Solution03 {
    public ListNode mergeNodes(ListNode head) {
        ListNode newlist = new ListNode(), p = newlist;
        int num = 0;
        for (var q = head.next; q != null; q = q.next) {
            if (q.val == 0) {
                p = p.next = new ListNode(num);
                num = 0;
            } else {    //
                num += q.val;
            }
        }
        p.next = null;

        return newlist.next;
    }
}
